<template>
  <el-dialog
    title="返利信息"
    :visible.sync="isVisible"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    :modal-append-to-body="false"
    width="30%"
    center
    @close="closeDialog"
  >
    <el-form :model="copyRebateInfo" :label-width="dialog.formLabelWidth">
      <el-form-item :label="copyLabel.gameName">
        <el-input v-model="copyRebateInfo.gameName" autocomplete="off" :disabled="true"></el-input>
      </el-form-item>
      <el-form-item :label="copyLabel.serverName">
        <el-input v-model="copyRebateInfo.serverName" autocomplete="off" :disabled="true"></el-input>
      </el-form-item>
      <el-form-item :label="copyLabel.username">
        <el-input v-model="copyRebateInfo.username" autocomplete="off" :disabled="true"></el-input>
      </el-form-item>
      <el-form-item :label="copyLabel.roleName">
        <el-input v-model="copyRebateInfo.roleName" autocomplete="off" :disabled="true"></el-input>
      </el-form-item>
      <el-form-item :label="copyLabel.roleId">
        <el-input autocomplete="off" :disabled="true" v-model="copyRebateInfo.roleId"></el-input>
      </el-form-item>
      <el-form-item :label="copyLabel.amount">
        <el-input v-model="copyRebateInfo.amount" autocomplete="off" :disabled="true"></el-input>
      </el-form-item>
      <el-form-item :label="copyLabel.payTime">
        <el-input v-model="copyRebateInfo.payTime" autocomplete="off" :disabled="true"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="onCopy" type="primary" plain>复 制</el-button>
    </div>
  </el-dialog>
</template>
<script>
export default {
  name: "showDebateDialog",
  data() {
   return {
      isVisible: this.isShow,
      copyRebateInfo: Object,
      //详情弹框信息
      dialog: {
        formLabelWidth: "120px"
      },
      copyLabel: {
        gameName: "游戏",
        serverName: "区服",
        username: "账号",
        roleName: "角色",
        roleId: "ID",
        amount: "充值金额",
        payTime: "充值时间"
      },
      copyObject: {
        gameName: "",
        serverName: "",
        username: "",
        roleName: "",
        roleId: "",
        amount: "",
        payTime: ""
      },
      newCopyObject:{

      }
    };
  },
  props: {
    isShow: Boolean,
    dialogRow: Object
  },
  methods: {
   onCopy() {
      // 将键换成中文
      Object.keys(this.copyObject).forEach(key => {
        this.newCopyObject[this.copyLabel[key]] = this.copyObject[key];
      });
      var str = JSON.stringify(this.newCopyObject);
      str = str.slice(1, -1);
      str = str.replace(/,/g, "\n");
      str = str.replace(/\"/g, "");
      this.$copyText(str).then(
        (e)=>{
          this.$message({
            message: "复制成功",
            type: "success"
          });
        },
        function(e) {
        }
      );
      this.isVisible = false;
    },
    closeDialog() {
      this.$emit("closeDialog");
    }
  },
  created() {
    this.copyRebateInfo = this.dialogRow;
    Object.keys(this.copyRebateInfo).forEach(key => {
      if (this.copyObject.hasOwnProperty(key)) {
        this.copyObject[key] = this.copyRebateInfo[key];
      }
    });  
  }
};
</script>